package com.lagou.service.impl;

import com.lagou.dao.AccountDao;
import com.lagou.domain.Account;
import com.lagou.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.sql.SQLException;
import java.util.List;

@Service(value = "accountService") //相当于配置了bean标签 id属性 class属性
@Scope("singleton")

public class AccountServiceImpl implements AccountService {

    @Autowired //根据类型进行注入
    //@Qualifier("accountDao")
    private AccountDao accountDao;

    @Value("注入普通属性")
    private String str;
    @Value("${jdbc.driverClassName}")
    private String driver;

    @PostConstruct
    public void init(){
        System.out.println("初始化方法...");
    }

    @PreDestroy
    public void destory(){
        System.out.println("销毁方法...");
    }

    @Override
    public List<Account> findAll() throws SQLException {
        System.out.println(str);
        System.out.println(driver);
        return accountDao.findAll();
    }

    @Override
    public Account findById(Integer id) {
        return accountDao.findById(id);
    }

    @Override
    public void save(Account account) {
        accountDao.save(account);
    }

    @Override
    public void update(Account account) {
        accountDao.update(account);
    }

    @Override
    public void delete(Integer id) {
        accountDao.delete(id);
    }
}
